package controllers;

import helpers.StringHelper;
import helpers.UrlHelper;

import java.io.IOException;
import java.util.TreeMap;

import javax.servlet.http.*;

import com.google.gson.Gson;

import models.ApiConfigModel;
import entities.ApiConfig;

@SuppressWarnings("serial")
public class HomeServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		
		String c = (String) request.getParameter("c");
		
		if (c != null && !c.isEmpty()) {
			ApiConfigModel apiConfigModel = ApiConfigModel.getInstance();
			ApiConfig apiConfig = apiConfigModel.get(c);
			
			//apiConfig.setCustomSelecter(apiConfig.getCustomSelecter().replaceAll("[\r\n\t]", ""));
			
			String json = new Gson().toJson(apiConfig);
			
			response.setContentType("application/json");
			response.getWriter().println(json);
			
		} else {
			response.setContentType("text/html");
			response.getWriter().println("hello the world");
		}
	}
	
	public static void main(String[] args) {
		String txt = "\r\n\t \t\r\n\t \t\r\n\t \t\r\n\t \t\r\n\t//Js function must return array of string link\r\n\tfunction beforePost(document)\r\n\t{\r\n\t var data = new Array();\r\n \r\n data['metaDesc'] = document.select('meta[name=description]').attr('content');\r\n data['metaKeyWords'] = document.select('meta[name=KeyWords]').attr('content');\r\n \r\n\t data['title'] = document.select('#domain_highlight').text();\r\n\t\r\n\t data['content'] =document.select('#domain_address_container .li_email > div:first-child').html();\r\n\t return data;\r\n\t} \t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
		
		txt = txt.replaceAll("[\r\n\t]", "");
		System.out.println(txt);
	}
}
